﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TeamBuy.AccessWebUI.Help
{
    public partial class Consultation : System.Web.UI.Page
    {
        int currentDealID;
        //public static string query;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (TeamBuySession.IsUserLoggedIn == true)
            {
                pnlLogin.Visible = true;
                pnlNotLogin.Visible = false;
            }
            else
            {
                pnlLogin.Visible = false;
                pnlNotLogin.Visible = true;
            }
            if (Request.QueryString["Show"] != null && Request.QueryString["Show"] != "")
            {
                if (Convert.ToString(Request.QueryString["Show"]) == "All")
                {
                    ltlAllStyle.Text = "class='current'";
                    ltlMyStyle.Text = "";
                    adsQuestion.SelectCommand = "SELECT * FROM [vw_QuestionInfo] WHERE ([CityID] = " + ((Components.Head)(Master.Master.FindControl("Head1"))).CurrentCityID + ") order by QuestionID DESC";

                }
                else if (Convert.ToString(Request.QueryString["Show"]) == "My")
                {
                    ltlAllStyle.Text = "";
                    ltlMyStyle.Text = "class='current'";
                    adsQuestion.SelectCommand = "SELECT * FROM [vw_QuestionInfo] WHERE ([CityID] = " + ((Components.Head)(Master.Master.FindControl("Head1"))).CurrentCityID + ") AND UserID=" + Convert.ToInt32(Session["UserID"]) + " order by QuestionID DESC";
                }
                else
                {
                    ltlAllStyle.Text = "class='current'";
                    ltlMyStyle.Text = "";
                    adsQuestion.SelectCommand = "SELECT * FROM [vw_QuestionInfo] WHERE ([CityID] = " + ((Components.Head)(Master.Master.FindControl("Head1"))).CurrentCityID + ") order by QuestionID DESC";
                }
            }
            else
            {
                ltlAllStyle.Text = "class='current'";
                ltlMyStyle.Text = "";
                adsQuestion.SelectCommand = "SELECT * FROM [vw_QuestionInfo] WHERE ([CityID] = " + ((Components.Head)(Master.Master.FindControl("Head1"))).CurrentCityID + ") order by QuestionID DESC";
            }
            if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "")
            {
                currentDealID = Convert.ToInt32(TeamBuy.Common.PublicFunction.DESDecrypt(Request.QueryString["ID"].ToString()));
            }
        }

        protected void btnSubmitQuestion_Click(object sender, EventArgs e)
        {
            TeamBuy.AccessService.TeamBuyQuestionService createQuestion = new AccessService.TeamBuyQuestionService();
            createQuestion.CreateQuestion(Convert.ToInt32(Session["UserID"]), ((Components.Head)Page.Master.Master.FindControl("Head1")).CurrentCityID, currentDealID, txtQuestion.Text);
            txtQuestion.Text = "";
            lbtnMy_Click(null, null);
        }

        protected void lbtnAll_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "")
            {
                Response.Redirect("Consultation.aspx?Show=All&ID=" + Request.QueryString["ID"].ToString());
            }
            else
            {
                Response.Redirect("Consultation.aspx?Show=All");
            }
            //ltlAllStyle.Text = "class='current'";
            //ltlMyStyle.Text = "";
            //adsQuestion.SelectCommand = "SELECT * FROM [vw_QuestionInfo] WHERE ([CityID] = " + ((Components.Head)(Master.Master.FindControl("Head1"))).CurrentCityID + ") order by QuestionID DESC";
            //query = adsQuestion.SelectCommand;
        }

        protected void lbtnMy_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "")
            {
                Response.Redirect("Consultation.aspx?Show=My&ID=" + Request.QueryString["ID"].ToString());
            }
            else
            {
                Response.Redirect("Consultation.aspx?Show=My");
            }
            //ltlAllStyle.Text = "";
            //ltlMyStyle.Text = "class='current'";
            //adsQuestion.SelectCommand = "SELECT * FROM [vw_QuestionInfo] WHERE ([CityID] = " + ((Components.Head)(Master.Master.FindControl("Head1"))).CurrentCityID + ") AND UserID=" + Convert.ToInt32(Session["UserID"]) + " order by QuestionID DESC";
            //query = adsQuestion.SelectCommand;
        }
    }
}